from xml.dom.minidom import Document
import zmq
import time
import numpy as np
# Local imports
#import bluesky as bs
#from bluesky import stack
#from bluesky.tools import areafilter
#from bluesky.core.walltime import Timer
import zmq
import time
import sys

#下面这部分是打印xml文件头部公共区域（苏雨）
doc = Document() #创建DOM文档对象（苏雨）
PropertyList = doc.createElement('PropertyList') #创建根元素（苏雨）
doc.appendChild(PropertyList)
generic = doc.createElement('generic')#book:Python处理XML之Minidom（苏雨）
PropertyList.appendChild(generic)
input = doc.createElement('input')
generic.appendChild(input)

line_separator = doc.createElement('line_separator')
line_separator_text = doc.createTextNode('newline')
line_separator.appendChild(line_separator_text)
input.appendChild(line_separator)

var_separator = doc.createElement('var_separator')
var_separator_text = doc.createTextNode('tab')
var_separator.appendChild(var_separator_text)
input.appendChild(var_separator)


chunk = doc.createElement('chunk')
input.appendChild(chunk)

name = doc.createElement('name')
name_text = doc.createTextNode('target_spd')
chunk.appendChild(name)
name.appendChild(name_text)

type = doc.createElement('type')
type_text = doc.createTextNode('float')
chunk.appendChild(type)
type.appendChild(type_text)

node = doc.createElement('node')
node_text = doc.createTextNode('/ai/models/aircraft/controls/flight/target-spd')
chunk.appendChild(node)
node.appendChild(node_text)


chunk = doc.createElement('chunk')
input.appendChild(chunk)

name = doc.createElement('name')
name_text = doc.createTextNode('target_alt')
chunk.appendChild(name)
name.appendChild(name_text)

type = doc.createElement('type')
type_text = doc.createTextNode('float')
chunk.appendChild(type)
type.appendChild(type_text)

node = doc.createElement('node')
node_text = doc.createTextNode('/ai/models/aircraft/controls/flight/target-alt')
chunk.appendChild(node)
node.appendChild(node_text)


chunk = doc.createElement('chunk')
input.appendChild(chunk)

name = doc.createElement('name')
name_text = doc.createTextNode('target_hdg')
chunk.appendChild(name)
name.appendChild(name_text)

type = doc.createElement('type')
type_text = doc.createTextNode('float')
chunk.appendChild(type)
type.appendChild(type_text)

node = doc.createElement('node')
node_text = doc.createTextNode('/ai/models/aircraft/controls/flight/target-hdg')
chunk.appendChild(node)
node.appendChild(node_text)


chunk = doc.createElement('chunk')
input.appendChild(chunk)

name = doc.createElement('name')
name_text = doc.createTextNode('lateral_mode')
chunk.appendChild(name)
name.appendChild(name_text)

type = doc.createElement('type')
type_text = doc.createTextNode('string')
chunk.appendChild(type)
type.appendChild(type_text)

node = doc.createElement('node')
node_text = doc.createTextNode('/ai/models/aircraft/controls/flight/lateral-mode')
chunk.appendChild(node)
node.appendChild(node_text)


##################################################################这里开始就可以循环添加了（苏雨）#######################################################################3
ai_num = 1 


chunk = doc.createElement('chunk')
input.appendChild(chunk)

name = doc.createElement('name')
name_text = doc.createTextNode('target_spd')
chunk.appendChild(name)
name.appendChild(name_text)

type = doc.createElement('type')
type_text = doc.createTextNode('float')
chunk.appendChild(type)
type.appendChild(type_text)

node = doc.createElement('node')
node_text = doc.createTextNode('/ai/models/aircraft[%d]/controls/flight/target-spd'%ai_num)
chunk.appendChild(node)
node.appendChild(node_text)


chunk = doc.createElement('chunk')
input.appendChild(chunk)

name = doc.createElement('name')
name_text = doc.createTextNode('target_alt')
chunk.appendChild(name)
name.appendChild(name_text)

type = doc.createElement('type')
type_text = doc.createTextNode('float')
chunk.appendChild(type)
type.appendChild(type_text)

node = doc.createElement('node')
node_text = doc.createTextNode('/ai/models/aircraft[%d]/controls/flight/target-alt'%ai_num)
chunk.appendChild(node)
node.appendChild(node_text)


chunk = doc.createElement('chunk')
input.appendChild(chunk)

name = doc.createElement('name')
name_text = doc.createTextNode('target_hdg')
chunk.appendChild(name)
name.appendChild(name_text)

type = doc.createElement('type')
type_text = doc.createTextNode('float')
chunk.appendChild(type)
type.appendChild(type_text)

node = doc.createElement('node')
node_text = doc.createTextNode('/ai/models/aircraft[%d]/controls/flight/target-hdg'%ai_num)
chunk.appendChild(node)
node.appendChild(node_text)


chunk = doc.createElement('chunk')
input.appendChild(chunk)

name = doc.createElement('name')
name_text = doc.createTextNode('lateral_mode')
chunk.appendChild(name)
name.appendChild(name_text)

type = doc.createElement('type')
type_text = doc.createTextNode('string')
chunk.appendChild(type)
type.appendChild(type_text)

node = doc.createElement('node')
node_text = doc.createTextNode('/ai/models/aircraft[%d]/controls/flight/lateral-mode'%ai_num)
chunk.appendChild(node)
node.appendChild(node_text)




        
         
#将DOM对象doc写入文件，可以指定特定路径和文件名（苏雨）
f = open('/home/suyu/suyu/FlightGear_connector/protocol/TEST.xml','w')#可以在这里修改xml文件的存储路径（苏雨）
f.write(doc.toprettyxml(indent = ''))
f.close()

                                 



















